/// <reference name="MicrosoftAjax.js"/>
var compileClasses=function(classObj){	
	for(var className in classObj)	{		
		var classGen = className + "=function(){\n";		
		var _constructor = "";		
		var privateMembers = "";		
		var publicMembers = "";		
		var staticMembers = "";		
		var statics = "";		
		var publics = "";		
		var parentClass = "";		
		var hasConstructor = false;		
		var thisClassDef = classObj[className];		
		var interfaces = [];		
		for(typ in thisClassDef) {			
			if(typ.toString().toLowerCase() == "ctor") {
				hasConstructor = true;				
				var cons = thisClassDef[typ];				
				_constructor += "var __CONSTRUCTOR = " + cons.toString() + "\n";
			}			
			else if(typ.toString().toLowerCase() == "private") {
				var privateMemObj = thisClassDef[typ];
				for(privateMember in privateMemObj) {
					var prvItem = privateMemObj[privateMember];
					_constructor += "var " + privateMember + " = ";
					if(typeof(prvItem) ==  "string")
						_constructor += "'" + prvItem + "';\n";
					else							
						_constructor += prvItem.toString() +";\n";
				}			
			} 			
			else if(typ.toString().toLowerCase() == "public") {					
				var publicMemObj = thisClassDef[typ];
				for(publicMember in publicMemObj) {
					var thisPublic = publicMemObj[publicMember];
					if(publics.length > 0)
						publics +=",\n";
					publics += publicMember + ":";
					if(typeof(thisPublic) == "string")
						publics += "'" + thisPublic + "'\n";
					else							
						publics += thisPublic.toString() +"\n";
				}			
			} 			
			else if(typ.toString().toLowerCase() == "static") {
				var staticMemObj = thisClassDef[typ];
				for(staticMember in staticMemObj) {
					statics += className + "." + staticMember + "=";
					var statItem = staticMemObj[staticMember];
					if(typeof(statItem) == "string")
						statics += "'" + statItem + "';\n";
					else							
						statics += statItem.toString() + ";\n";					
				}			
			} 			
			else if(typ.toString().toLowerCase() == "inherits") {					
				parentClass = thisClassDef[typ];			
			}			
			else if(typ.toString().toLowerCase() == "implements") {
				interfaces = thisClassDef[typ];
			}		
		}					
		if(hasConstructor)
			_constructor += "__CONSTRUCTOR.call(this, arguments);\n";
		classGen += _constructor + "}\n";		
		classGen += className +".prototype ={\n" + publics + "};\n";
		classGen += statics;
		// Need to handle the inheritance chain		
		if(parentClass.toLowerCase() != "interface") {			
			classGen += className + ".registerClass('" + className + "'";
			if(parentClass !="")
				classGen += ", " + parentClass;
			else				
				classGen += ", null";			
			if(typeof(interfaces) != "undefined" && interfaces.length > 0 && typeof(interfaces[0]) !="undefined" && interfaces[0].toString() !="")
				classGen += "," + interfaces.join(",");
			classGen += ");\n";		
		}		
		else		
		{			
			if(typeof(interfaces) != "undefined" && interfaces.length > 0 && typeof(interfaces[0]) !="undefined" && interfaces[0].toString() !="")				
				classGen += "var" + interfaces[0] + " = ";			
			classGen += className + ".registerInterface('" + className + "');\n";		
		}				
		Sys.Debug.trace(classGen);		
		eval(classGen);	
	}
}